﻿using System;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using AnyOffice.Model;


namespace AnyOffice.general.chatroom
{
    public partial class login : ModulePage
    {

 
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                int sessionId = (Request.QueryString["session_id"] != null) ? int.Parse(Request.QueryString["session_id"]) : 0;
                this.ViewState["SessionId"] = sessionId;
                DataTable table = new ChatSessionsDao().SelectBySessionId(base.Conn, sessionId);
                if (table.Rows.Count > 0)
                {
                    this.litNavTitle.Text = table.Rows[0]["SessionName"].ToString();
                }
                UserCache cache = new UserCache();
                this.txtNickName.Value = cache.NickName;
            }
            if (this.Page.IsPostBack)
            {
                ChatUserDao dao2 = new ChatUserDao();
                ChatUserData data = new ChatUserData();
                data.UserId = base.User.Identity.Name;
                data.SessionId = Convert.ToInt32(this.ViewState["SessionId"]);
                data.NickName = this.txtNickName.Value;
                dao2.Insert(base.Conn, data);
                base.CloseConn();
                Response.Redirect("chat.aspx?session_id=" + this.ViewState["SessionId"].ToString());
            }
        }
 

    }
}
